package com.qf.controller;

import com.qf.pojo.Emp;
import com.qf.service.EmpService;
import com.qf.service.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 跳转到修改页面
 * @author 千锋健哥
 */
@WebServlet("/jumpUpdate")
public class JumpUpdateEmpController extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1. 获取要修改的主键id
        String id = req.getParameter("id");

        //2. 根据主键id调用service查询数据
        EmpService empService = new EmpServiceImpl();
        Emp emp = empService.findOne(Integer.parseInt(id));

        //3. 返回查询到的数据, 到修改页面, 回显数据
        req.setAttribute("emp", emp);
        //跳转到修改页面
        req.getRequestDispatcher("/update.jsp").forward(req, resp);
    }

}
